# -*- coding: utf-8 -*-
import scrapy
# import requests
from  lxml import etree
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
from dj.items import DjItem

class DdjjSpiderSpider(CrawlSpider):
    name = 'ddjj_spider'
    allowed_domains = ['dajie.com']
    start_urls = ['https://job.dajie.com/']
    # restrict_xpath = '//p[@class="hn-detail-title"]/a/@id'
    rules = (
        # Rule(LinkExtractor(allow=r'[a-zA-z]+://job.dajie.com/job/search\?positionFunction=\d+&positionName=[\u4e00-\u9fa5]+'),callback='parse', follow=True),
        # Rule(LinkExtractor(restrict_xpaths='job/search?positionFunction=//p[@class="hn-detail-title"]/a/@id'),callback='parse', follow=True),
        Rule(LinkExtractor(allow=r'[a-zA-z]+://job.dajie.com/\w+1'),callback='parse', follow=True),

        # Rule(LinkExtractor(allow=r'[a-zA-z]+://job.dajie.com/\w+.html'), callback='parse_list',follow=False),
    )

    def parse(self, response):
        name = response.xpath('//div[@class="jobList"]/ul/li/@data-url').extract()
        # print(response.body.decode('utf-8'))
        print(name)

    def parse_list(self, response):
        # name = response.xpath('//span[@class="job-name"]/text()').extract()
        # print(name)
        print(response.url)
